#include <bits/stdc++.h>
using namespace std;
const int N=2100;
int T;
long long dp[N][N]={},a[N]={},n;
void solve(){
    memset(dp,0,sizeof(dp));
    memset(a,0,sizeof(a));
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i == j)continue;
            else if(i==0){
                long long te=0;
                if(a[j-1] == a[j])te=a[j];
                dp[i][j]=dp[i][j-1]+te;
            }
            else if(j==0){
                long long te=0;
                if(a[i-1] == a[i])te=a[i];
                dp[i][j]=dp[i-1][j]+te;
            }
            else if(i<j){
                if(j-i == 1){
                    for(int k=0;k<=i-1;k++){
                        long long te=0;
                        if(a[k] == a[j])te=a[k];
                        dp[i][j]=max(dp[i][k]+te,dp[i][j]);
                    }
                }
                else {
                    long long te=0;
                    if(a[j-1] == a[j])te=a[j];
                    dp[i][j]=dp[i][j-1]+te;
                }
            }
            else if(i>j){
                if(i-j == 1){
                    for(int k=0;k<=j-1;k++){
                        long long te=0;
                        if(a[k] == a[i])te=a[k];
                        dp[i][j]=max(dp[k][j]+te,dp[i][j]);
                    }
                }
                else {
                    long long te=0;
                    if(a[i-1] == a[i])te=a[i];
                    dp[i][j]=dp[i-1][j]+te;
                }
            }

        }
    }
    long long ans=0;
    for(int i=0;i<=n;i++){
        ans=max(ans,dp[i][n]);
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)solve();
    return 0;
}
